<?php


namespace app\zmt\controller;


use app\zmt\model\NavModel;
use cmf\controller\AdminBaseController;

class NavController extends AdminBaseController
{
        public function index(){
            $model = NavModel::select();
            return $this->fetch('index',[
                'data' =>$model,
            ]);
        }
        public function order(){
            parent::listOrders(new NavModel());
            $this->success('排序成功');
        }
        public function totolgSwitch(){
            $id = input('id/d');
            $user = NavModel::find($id);
            if (!$user) {
                $this->error('主题不存在');
            }
            // 切换状态
            $user->switch = $user->switch ? 0 : 1;
            if ($user->save()) {
                $this->success('切换成功');
            } else {
                $this->error('切换失败');
            }
        }
        public function add(){
            return $this->fetch();
        }
        public function addPost(){
            $data = input('post.');
            $data['create_time'] = time();
            if (NavModel::create($data)){
                $this->success('添加主题成功');
            }else{
                $this->error('添加主题失败');
            }
        }
        public function delete(){
            $id = input('id');
            if (NavModel::destroy($id)){
                $this->success('删除成功');
            }else {
                $this->success('删除成功');
            }
        }
}